-- require 'Common/define'
-- require 'Logic/Config'
-- require 'Common/functions'

-- UIRobRecord = {}
-- HelperFunc.SetUIEnv(UIRobRecord)
-- local this = UIRobRecord

-- function UIRobRecord.Init(data, closeFunc) 
--     local _name, _package = getUIName(PanelNames.UIRobRecord)
--     panelMgr:ShowUI(_name, _package, this.onCreate, Config.useLocalUI)
-- end

-- function UIRobRecord.onCreate(obj) 
--     if not this.hasInit then
--         this.hasInit = true 
--         this.btn_back = obj:GetChild("Btn_BackButton")
--         this.btn_bg_back = obj:GetChild("Btn_BgClose")
--         -- local com_threebg = obj:GetChild("Com_ThreeBg")
--         -- this.title = com_threebg:GetChild("title") 
--         this.list_rob_record = obj:GetChild("List_RobRecord")
--         this.list_show = obj:GetController("list_show")
--         this.list_rob_record.itemRenderer = this.UpdateItemRender
--         this.addEvent()
--     end 
--     this.initData()
-- end
 
-- function UIRobRecord.initData()   
--     this.item_rewards = nil
--     this.rob_record_over_time = dataTable.getDataTableByStringId("t_global", 336 ,"f_int_value") 
--     this.cur_history_list = {}
--     this.timer_list = {}
--     this.list_rob_record.numItems = 0
--     this.list_show:SetSelectedIndex(1) 
--     plunderHandler.sendReqRobList( 1 ) -- 掠夺记录
-- end

-- function UIRobRecord.ResUpdateRobRecordInfo( msg )
--     if msg and msg.list and next(msg.list) ~= nil then
--         this.cur_history_list = {}
--         for _, v in pairs(msg.list) do
--             table.insert(this.cur_history_list, v)
--         end
--         if #this.cur_history_list > 0 then
--             this.list_show:SetSelectedIndex(0)
--         else
--             this.list_show:SetSelectedIndex(1)
--         end
--         this.list_rob_record.numItems = #this.cur_history_list

--     else
--         this.list_rob_record.numItems = 0
--         this.list_show:SetSelectedIndex(1)
--     end
-- end


-- -- <field class="long" name="id" explain="唯一id"></field>
-- -- <field class="long" name="playerId" explain="玩家id"></field>
-- -- <field class="String" name="name" explain="玩家名字"></field>
-- -- <field class="String" name="pic" explain="角色头像"></field>
-- -- <field class="int" name="picFrame" explain="头像框"></field>
-- -- <field class="int" name="lv" explain="等级"></field>
-- -- <field class="int" name="type" explain="类型 1被掠夺 2被复仇"></field>
-- -- <field class="com.game.battle.bean.BattleRecord" name="record" explain="战斗记录"></field>
-- function UIRobRecord.UpdateItemRender( index, obj )   
   
--     if this.timer_list[index] ~= nil then
--         utimer.remove(this.timer_list[index])
--         this.timer_list[index] = nil
--     end

--     local item_info = this.cur_history_list[index + 1] 

--     -- item_info = {}
--     -- item_info.type = 1
--     -- item_info.pic = "1"
--     -- item_info.picFrame = "2"
--     -- item_info.items = {}
--     -- item_info.name = "名字"
--     -- item_info.record = {}
--     -- item_info.record.createTime = "1622876690000"
--     -- item_info.record.defender = {}
--     -- item_info.record.attacker = {} 

--     if item_info then
--         local btn_head = obj:GetChild("Btn_Head")
--         btn_head.onClick:Clear()
--         btn_head:GetChild("head"):GetChild("HeadIcon").url = EnumConst.AtlasPath.ICONAtlas .."icon_hero_" .. item_info.pic 
--         btn_head:GetChild("frame").url = EnumConst.AtlasPath.ICONAtlas .. item_info.picFrame 

--         local btn_robitem = {}
--         btn_robitem[1] = obj:GetChild("Btn_RobItem01")
--         btn_robitem[2] = obj:GetChild("Btn_RobItem02")
--         btn_robitem[3] = obj:GetChild("Btn_RobItem03")
--         btn_robitem[1].visible = false
--         btn_robitem[2].visible = false
--         btn_robitem[3].visible = false
--         local sub_items = item_info.items  
--         local sub_index = 1
--         for i = 1,  3 do 
--             if sub_items[i] ~= nil then 
--                 this.showItemData(btn_robitem[sub_index], sub_items[i] )
--                 sub_index = sub_index+1
--             end
--         end
 
--         local txt_player_name = obj:GetChild("Text_PlayerName")
--         txt_player_name.text = item_info.name or ""

--         local txt_fight_time = obj:GetChild("Text_FightTime")
--         local create_time = tonumber(tostring(item_info.record.createTime))
--         txt_fight_time.text = getTimeStrType2(create_time)

--         local btn_record = obj:GetChild("Btn_Record")
--         btn_record.onClick:Clear()
--         btn_record.onClick:Add(function()
--             showUI(PanelNames.UILevelRecode, EnumConst.FightTypeConst.Plunder, item_info.record)
--         end) 
 
--         local btn_receive = obj:GetChild("Btn_Get") 
--         btn_receive.onClick:Clear() 
--         btn_receive.onClick:Add(function()
--             this.item_rewards = sub_items
--             this.onClickReceiveReward( item_info )
--         end)  

--         local rob_controller = obj:GetController("Rob")
--         if item_info.type == 1 then -- 被掠夺
--             rob_controller:SetSelectedIndex(0)
--         elseif item_info.type == 2 then -- 被复仇
--             rob_controller:SetSelectedIndex(1)
--         else
--             rob_controller:SetSelectedIndex(2)
--         end

--         if item_info.type == 2 then -- 被复仇
--             rob_controller:SetSelectedIndex(2)
--         else
--             local revenge_end_time = create_time + this.rob_record_over_time 
--             local dis_time = revenge_end_time - Config.serverTime
--             if dis_time > 0 then 
--                 rob_controller:SetSelectedIndex(1)
--                 dis_time = math.ceil(dis_time/1000)
--                 local txt_wait_time = obj:GetChild("Text_GetTime") 
--                 txt_wait_time.text = string.format(getLanguage("RogueTips04"), timeToTimeFormat2(dis_time)) --"等待对手反击\n"..timeToTimeFormat(dis_time)
--                 this.timer_list[index] = utimer.timeCall(function() 
--                     dis_time = dis_time -1 
--                     if txt_wait_time then 
--                         txt_wait_time.text = string.format(getLanguage("RogueTips04"), timeToTimeFormat2(dis_time)) --"等待对手反击\n"..timeToTimeFormat(dis_time)
--                     end
--                     if dis_time <= 0 then
--                         rob_controller:SetSelectedIndex(0)
--                         utimer.remove(this.timer_list[index])
--                         this.timer_list[index] = nil
--                         this.UpdateRedDot() 
--                     end
--                 end, 1000, dis_time) 
--             else 
--                 rob_controller:SetSelectedIndex(0)
--             end
--         end
--     end
-- end

-- function UIRobRecord.UpdateRedDot() 
--     FireEvent(Config.EventType.Fresh_WorldMapReceiveRobReward)
-- end

-- -- 显示道具
-- function UIRobRecord.showItemData(obj, data ) 
--     if data ~= nil then
--         obj.visible = true
--         local img_Quality = obj:GetChild("quality")
--         local img_Frame = obj:GetChild("frame")
--         local img_Icon = obj:GetChild("icon")
--         local txt_num = obj:GetChild("num")
--         local name = obj:GetChild("name")
--         local cornerMark = obj:GetChild("cornerMark")
--         local ctrlSuit = obj:GetController("suit")  
--         local ctrlMirror = obj:GetController("heroMirror")
--         local cornerMarkController = obj:GetController("cornerMark")
--         if cornerMarkController then
--             cornerMarkController.selectedIndex = 0
--         end

--         UIComponentInterface:SetItemAllById(img_Icon, img_Quality, img_Frame, data.itemModelId)
--         local constData = ItemManager.getItemConstDatabyModelId(data.itemModelId)
--         if constData and constData.itemType == EnumConst.ItemTypeEnum.Title then
--             img_Icon.url = EnumConst.AtlasPath.ICONAtlas .. constData.icon 
--         end
--         if ctrlMirror then
--             if constData and constData.icon and constData.itemType == EnumConst.ItemTypeEnum.Hero then
--                 img_Icon.url = EnumConst.AtlasPath.ICONAtlas .. constData.icon
--                 ctrlMirror.selectedIndex = 1
--             else
--                 ctrlMirror.selectedIndex = 0
--             end
--         end
--         if constData and constData.cornerMark ~= "" then
--             if cornerMarkController then
--                 cornerMarkController.selectedIndex = 1
--             end
--             if cornerMark then
--                 cornerMark.url = EnumConst.AtlasPath.ICONAtlas .. constData.cornerMark;
--             end
--         end
--         if ctrlSuit then
--             if logicMgr.ItemManager.IsEquip(data.itemModelId) then
--                 local cfg = dataTable.getDataTableByStringId("t_equip",data.itemModelId)
--                 ctrlSuit.selectedIndex = cfg.f_EquipSuit 
--             else
--                 ctrlSuit.selectedIndex = 0
--             end
--         end
  
--         if txt_num then
--             if data.num ~= nil and data.num ~= "" then
--                 if logicMgr.ItemManager.IsEquip(data.itemModelId) then
--                     if tonumber(data.num) == 1 then
--                         txt_num.text = ""
--                     else
--                         txt_num.text = getNumString(tonumber(data.num))
--                     end
--                 else
--                     txt_num.text = getNumString(tonumber(data.num))
--                 end
--             else
--                 txt_num.text = ""
--             end
--         end
--     else
--         obj.visible = false
--     end
-- end

-- function UIRobRecord.onClickReceiveReward( item_info )   
--     plunderHandler.sendReqGetPlunderRewardMessage( item_info.id )  
-- end

-- function UIRobRecord.ResPlunderRobReward( msg )  
--     plunderHandler.sendReqRobList( 1 ) -- 掠夺记录
--     if this.item_rewards ~= nil and next(this.item_rewards) ~= nil then
--         showUI(PanelNames.UICommonItemGet, nil, nil, 3, this.item_rewards)
--         this.item_rewards = nil
--     end
-- end

-- function UIRobRecord.addEvent() 
--     this.btn_back.onClick:Add(this.CloseSelf) 
--     this.btn_bg_back.onClick:Add(this.CloseSelf)
-- end

-- function UIRobRecord.removeEvent() 
--     this.btn_back.onClick:Clear() 
--     this.btn_bg_back.onClick:Clear()
-- end

-- function UIRobRecord.CloseSelf() 
--     DestoryUI(PanelNames.UIRobRecord)
-- end
 
-- function UIRobRecord.OnDestroy() 
--     for k, v in pairs(this.timer_list) do
--         if this.timer_list[k] ~= nil then
--             utimer.remove(this.timer_list[k])
--             this.timer_list[k] = nil
--         end
--     end
--     this.removeEvent()
--     this.hasInit = nil
--     this.root = nil
--     this.list_show = nil
--     plunderHandler.is_revenge = nil
-- end

-- return UIRobRecord
